package com.java8.pangjunjie.lambad;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class Demo01 {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student s1 = new Student();
        s1.setId(1);
        s1.setName("name1");
        s1.setAge(22);
        list.add(s1);
        Student s2 = new Student();
        s2.setId(2);
        s2.setName("name2");
        s2.setAge(16);
        list.add(s2);
        Student s3 = new Student();
        s3.setId(3);
        s3.setName("name3");
        s3.setAge(33);
        list.add(s3);
        for(Student s:list){
            System.out.println(s);
        }

//        list.sort(new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return o1.getAge() - o2.getAge();
//            }
//        });

        list.sort((o1,o2)->o1.getAge() - o2.getAge());

        list.forEach(new Consumer<Student>() {
            @Override
            public void accept(Student student) {
                System.out.println(student);
            }
        });

        list.forEach(s-> System.out.println(s));




    }
}
